﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/HomeSite.Master" Inherits="System.Web.Mvc.ViewPage<TimeTableManagement.Entities.Tb_Role>" %>

<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxRoundPanel" TagPrefix="dx" %>

<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPanel" tagprefix="dx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<script src="<%: Url.Content("~/Scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
<script src="<%: Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js") %>" type="text/javascript"></script>

    <dx:ASPxRoundPanel ID="ASPxRoundPanel1" runat="server" Width="100%" 
        CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" HeaderText="Add Role"
        GroupBoxCaptionOffsetY="-28px" 
        SpriteCssFilePath="~/App_Themes/Aqua/{0}/sprite.css">
        <ContentPaddings Padding="14px" />
        <PanelCollection>
<dx:PanelContent runat="server" SupportsDisabledAttribute="True">
<% using (Html.BeginForm())
   { %>
   <%: Html.ValidationSummary(true) %>
        <div class="editor-label"><%: Html.LabelFor(model => model.rolename) %>
        </div>
        <div class="editor-field">
        <%: Html.EditorFor(model => model.rolename) %>
            <%: Html.ValidationMessageFor(model => model.rolename) %>
        </div>

        <div class="editor-label"><%: Html.LabelFor(model => model.description) %>
        </div>
        <div class="editor-field">
        <%: Html.EditorFor(model => model.description) %>
            <%: Html.ValidationMessageFor(model => model.description) %>
        </div>
        <div class="editor-field"> <%: Html.LabelFor(model => model.value) %> </div>
        <div class="editor-field">
            <table style="color:#333333;width:100%;border-collapse:collapse;">
                <tr style="color:White;background-color:#507CD1;font-weight:bold;">
                    <td class="style5">
                        Module</td>
                    <td class="style5">
                        View</td>
                    <td class="style5">
                        Create</td>
                    <td class="style5">
                        Edit</td>
                    <td class="style5">
                        Delete</td>
                    <td class="style5">Full</td>
                </tr>
     <% 
        
       TimeTableManagement.Entities.Tb_Role _role = new TimeTableManagement.Entities.Tb_Role();
       List<TimeTableManagement.Entities.Role> list = _role.getRoleModule(1);  
    %>
            <% int i = 0; foreach (TimeTableManagement.Entities.Role r in list)
               {
                   i++; %>
               <% if (i % 2 != 0)
                  { %>
            <tr style="background-color:#EFF3FB;">
            <% }
                  else
                  { %>
                  <tr style="background-color:White;">
            <% } %>
                    <td class="style2">
                        <%= r.t%> </td>
                    <td class="style5">
                        <input id="Checkbox<%= (i*10+1) %>" type="checkbox"/></td>
                    <td class="style5">
                        <input id="Checkbox<%= (i*10+2) %>" type="checkbox"/></td>
                    <td class="style5">
                        <input id="Checkbox<%= (i*10+3) %>" type="checkbox" /></td>
                    <td class="style5">
                        <input id="Checkbox<%= (i*10+4) %>" type="checkbox"/></td>
                        <%-- Trung chinh sua tai day --%>
                    <td class="style5">
                        <input id="Checkbox<%= (i*10+5) %>" type="checkbox" onclick ="selectAll(this)" /></td>
                        <script type="text/javascript">
                            function selectAll(pointer) {
                                $group = pointer.id.substr(0, 9);
                                $value = pointer.checked;
                                for (i = 1; i <= 4; i++) {
                                    $item = $group + i.toString();
                                    //alert($item);
                                    document.getElementById($item).checked = $value;

                                }
                            }
                        </script>
                        <%--Can mot xu ly Javascript, khi click vao checkbox5 thi 4 checkbox kia cung se duoc click--%>
                </tr>
                <% } %>
            </table>
    </div>
        <div class="editor-field"><%: Html.HiddenFor(model => model.value) %>
        <%--Can mot Javascript, khi co 1 check vao trong table, thi lap tuc thay doi gia tri cua chuoi tai day--%>
        <script>
            function updatejson() {
                $role = '[{"m":"sys","t":"System","r":' + countingpermission('1') + '},' +
                '{"m":"sch","t":"Information School","r":' + countingpermission('2') + '},' +
                '{"m":"stu","t":"Information Student","r":' + countingpermission('3') + '},' +
                '{"m":"lec","t":"Information Lecture","r":' + countingpermission('4') + '},' +
                '{"m":"cou","t":"Course","r":' + countingpermission('5') + '},' +
                '{"m":"roo","t":"Room","r":' + countingpermission('6') + '},' +
                '{"m":"tim","t":"Time Tablel","r":' + countingpermission('7') + '},' +
                '{"m":"new","t":"New","r":' + countingpermission('8') + '}]';
                document.getElementById('value').value = $role;
                return true;
            }
            function countingpermission($id) {
                $cout = 0;
                if (document.getElementById('Checkbox' + $id + '1').checked) {
                    $cout = $cout + 1;
                }
                if (document.getElementById('Checkbox' + $id + '2').checked) {
                    $cout = $cout + 2;
                }
                if (document.getElementById('Checkbox' + $id + '3').checked) {
                    $cout = $cout + 4;
                }
                if (document.getElementById('Checkbox' + $id + '4').checked) {
                    $cout = $cout + 8;
                }
                return $cout;
            }
        </script>
        </div>
        <p>
            <input type="submit" value="Create" onclick="return updatejson()" />
            <%--Can mot javascript, khi click vao nut Create thi xet trong table, de tao thanh mot String theo dinh dang Json.
            Gan gia tri String do cho HiddenField co ten la "value"--%>
        </p>

<div>
</div>
<% } %>

</dx:PanelContent>
</PanelCollection>
    </dx:ASPxRoundPanel>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">

     <style type="text/css">
        .style1
        {
            font-size: medium;
        }

        .style5
        {
            height: 18px;
            border-style:dotted;
            border-color:Aqua;
            text-align: center;
        }
        .style2
        {
            height: 18px;
            border:1;
            text-align: left;
        }
        </style>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="leftmenu" runat="server">
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="menuright" runat="server">
</asp:Content>

<asp:Content ID="Content5" ContentPlaceHolderID="Footer" runat="server">
</asp:Content>
